<?php
include('Db.php');
$db = new Db();
$url = 'https://www.xiaoyanger.net/api/list_new_site.json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data, true);
if($data['code'] == 0){
    foreach ($data['data'] as $key => $v) {
        $check = $db->table('dir_websites')->where('web_url',$v['site'])->find();
        if(!$check){
            $dir_websites = array(
                'user_id' => 1,
                'cate_id' => 1,
                'web_name' => $v['name'],
                'web_url' => $v['site'],
                'web_tags' => $v['keywords'] ? $v['keywords'] : $v['name'],
                'web_pic' => $v['logo'] ? $v['logo'] : 'https://pic.xiaoyanger.net/images/1/202509/68ba7cc4b5f82.png', // $v['pic'] 为截图  但是也可能没有
                'web_intro' => $v['description'] ? $v['description'] : $v['name'],
                'web_ispay' => 0,
                'web_istop' => 0,
                'web_isbest' => 0,
                'web_islink' => 1,
                'web_status' => 3,
                'web_ctime' => time(),
            );
            // 字符截取
            $dir_websites['web_tags'] = mb_substr($dir_websites['web_tags'],0,20,'utf-8');
            $db->table('dir_websites')->insert($dir_websites);
            $check = $db->table('dir_websites')->where('web_url',$v['site'])->find();
            $db->table('dir_webdata')->insert(array('web_id'=>$check['web_id']));
            print_r($dir_websites);
            exit();
        }
    }
}

